﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzureProvider.SoupMethods.MiniSensor;

namespace AzureProvider.MiniSensor
{
    public class Channels
    {
        string errMessage;
        ChannelMethods channel_methods = new ChannelMethods();
        /// <summary>
        /// Retrieves a channel from the data store.
        /// </summary>
        public  Channel SelectChannel(Guid id)
        {
            return (Channel)channel_methods.CreateObject(channel_methods.GetEntity(id.ToString(), out errMessage));
        }

        /// <summary>
        /// Inserts a new channel to the data store.
        /// </summary>
        public void InsertChannel(Channel channel)
        {
            channel_methods.Insert(channel, out  errMessage);
        }

        /// <summary>
        /// Updates a channel.
        /// </summary>
        public  void UpdateChannel(Channel channel)
        {
            channel_methods.Update(channel, out  errMessage);
        }
        /// <summary>
        /// Deletes a channel from the data store.
        /// </summary>
        public void DeleteChannel(Channel channel)
        {
            channel_methods.Delete(channel.Id.ToString());

        }

        public List<Channel> GetChannels()
        {
            List<Channel> channels = channel_methods.GetChannels(null, out errMessage).ToList();
            for (int i = 0; i < channels.Count; i++)
            {
                Channel channel = channels[i];
                channel_methods.FillMessages(ref channel, out errMessage);
            }
            return channels;
        }
        public List<Channel> GetListChannels()
        {
            List<Channel> channels = channel_methods.GetChannels(null, out errMessage).ToList();
            
            return channels;
        }
    }
}
